package com.example.controller;
import com.example.common.Result;
import com.example.controller.params.D01UploadDeviceDataParam;
import com.example.controller.params.QrcodesParam;
import com.example.model.Machine;
import com.example.model.MachineTx;
import com.example.model.Machine_test;
import com.example.service.MachineService;
import com.example.service.impl.MachineServiceImpl;
import com.example.utils.JacksonUtil;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/**
 * @ClassName SysUserController
 * @Description 用户信息Controller层
 * @Author chengjunyu
 * @Date 2022/1/24 11:18
 * @Version 1.0
 */
@RestController
@RequestMapping("/data")
public class MachineController {
    @Resource
    public MachineService machineService;

    @GetMapping("/selectById")
    public Machine selectMachine(int id) {
        Machine machine = machineService.selectMachineById(id);
        return machine;
    }

    @GetMapping("/selectByQrcode")
    public Machine selectMachineByQrcode(String qrcode) {
        return machineService.selectMachineByQrcode(qrcode);
       // MachineTx machineTx =  machineService.selectMachineByQrcode(qrcode);
       // return machineTx;
    }

    @GetMapping("/selectByQrcode2")
    public Machine selectMachineByQrcode2(String qrcode) {
         Machine machine = machineService.selectMachineByQrcode2(qrcode);

        if((machine.getLength_type().equals("")) && (!machine.getMachine_value().equals("")))
           machine.setLength_type(machine.getMachine_value());
         return machine;

    }

    /*
    其他设备
     */
    @GetMapping("/selectByQrcode3")
    public Machine selectMachineByQrcode3(String qrcode) {
        Machine machine = machineService.selectMachineByQrcode3(qrcode);
        return machine;
    }

    private static final List<String> includeKey =
            Arrays.asList("Height1","Height2");
    /*
   ZS-C-263项目取测试数据的某些测量值显示到length_type
    */
    @GetMapping("/selectByQrcode4")
    public Machine selectMachineByQrcode4(String qrcode) {
      //  machineTxList.
        return machineService.selectMachineByQrcode4(qrcode);
    }

    @GetMapping("/selectByType")
    public Machine selectMachineByType(Machine machine) {
        Machine machine2 = machineService.selectMachineByType(machine);
        return machine2;
    }

    @GetMapping("/selectDjByQrcode")
    public Machine selectMachineDjByQrcode(String qrcode) {
        Machine machine = machineService.selectMachineDjByQrcode(qrcode);
        return machine;

    }

    @PostMapping("/selectResult")
    public List<Machine>  selectMachineResult(@RequestBody List<String> param) {
        List<Machine>  machineList = machineService.selectMachineResult(param);
        return machineList;

    }

/*
    @GetMapping("/selectResult")
    public List<Machine>  selectMachineResult(List<String> qrCodes) {
        List<Machine>  machineList = machineService.selectMachineResult(qrCodes);
        return machineList;

    }
*/
    @GetMapping("/selectAll")
    public List<Machine> selectMachineList() {
       return machineService.selectMachineAll();
    }

    @PostMapping("/insertMachine")
    public Result insertMachine(@RequestBody Machine machine) {
        //写入结果
       // machineService.insertMachineResult(machine);
        int count = machineService.insertMachine(machine,null);
        if(count > 0) {

            return Result.ok("新增记录成功。。。");
        }
        return Result.error("新增记录失败。。。");

    }

    @PostMapping("/updateMachine")
    public String updateMachine(Machine machine) {
        int count = machineService.updateMachine(machine);
        if(count > 0) {
            return "修改记录成功。。。";
        }
        return "修改记录失败。。。";
    }

    @PostMapping("/deleteById")
    public String deleteMachine(int id) {
        int count = machineService.deleteMachineById(id);
        if(count > 0) {
            return "删除记录成功。。。";
        }
        return "删除记录失败。。。";
    }


};


